<template>
<!-- 开通协议（目前只有中顺易） -->
<el-dialog title="开通协议" :visible.sync="dialogVisible" :show-close="false" :close-on-click-modal="closeModal" :close-on-press-escape="closeEscape" :before-close="close">
  <!-- 中顺易协议 -->
  <div>
    <!-- `checked` 为 true 或 false -->
    <el-checkbox v-model="checked">我同意</el-checkbox>
    <el-link href="https://web.czb365.com/ty/merchant/agreement_zsy.html" target="_blank" type="primary">《团油-银行-加油站实时结算协议》 </el-link>
    <span> ，并申请开通团油-银行-加油站实时结算账户。</span>
  </div>
  <div slot="footer" class="dialog-footer">
    <el-button size="mini" @click="exitAuth">取消</el-button>
    <el-button type="primary" size="mini" :loading="submitLoading" @click="confirmSign">确认开通</el-button>
  </div>
</el-dialog>
</template>

<script>
import dialog from '@mix/dialog'
import { signAgreementApi } from '@api/finance'
export default {
  //判断：中顺易首次进入，提现时再次判断，未确认协议，确认协议
  mixins: [dialog],
  props: {

  },
  data() {
    return {
      checked: false,
      submitLoading: false
    }
  },
  methods: {
    //确认协议
    async confirmSign() {
      console.log('sign: ', this.checked)
      if (this.checked) {
        try {
          this.submitLoading = true
          const { code } = await signAgreementApi()
          if (code === 200) {
            this.$message.success('开通成功');
            this.submitLoading = false
            this.close()
          }else{
            this.submitLoading = false 
          }
        } catch (err) {
          this.submitLoading = false 
          console.log(err)
        }
      } else {
        this.$message.info('请阅读并同意勾选协议！');
      }
    },
    exitAuth(){
      this.$emit('exit')
    }
  }
}
</script>
